package com.fs.system.manager.controller;

import com.fs.system.college_admin.domain.CollegeAdmin;
import com.fs.system.college_admin.service.CollegeAdminService;
import com.fs.system.common.ResponseData;
import com.fs.system.exception.CustomerException;
import com.fs.system.manager.domain.Account;
import com.fs.system.student.domain.Student;
import com.fs.system.student.service.StudentService;
import com.fs.system.sys_admin.service.SysAdminService;
import com.fs.system.teacher.service.TeacherService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/manager")
public class WebController {

    @Resource
    private StudentService studentService;

    @Resource
    private CollegeAdminService collegeAdminService;

    @Resource
    private TeacherService teacherService;

    @Resource
    private SysAdminService sysAdminService;

    @PostMapping("/student/login")
    public ResponseData studentLogin(@RequestBody Account account){
        Map<String, Object> resMap = new HashMap<>();
        if("STUDENT".equals(account.getRole())){
            resMap = studentService.login(account);
        }
        else if(account.getRole() == null || "".equals(account.getRole())){
            throw new CustomerException("500","权限不合法");
        }else {
            throw new CustomerException("500","没有该角色");
        }
        return new ResponseData("200", "登录成功", resMap);
    }

    @PostMapping("/admin/login")
    public ResponseData adminLogin(@RequestBody Account account){
        Map<String, Object> resMap = new HashMap<>();
        if("SUPER_ADMIN".equals(account.getRole())){
            resMap = sysAdminService.login(account);
        }
        else if ("ADMIN".equals(account.getRole())){
            resMap = collegeAdminService.login(account);
        }
        else if ("TEACHER".equals(account.getRole())){
            resMap = teacherService.login(account);
        }
        else if(account.getRole() == null || "".equals(account.getRole())){
            throw new CustomerException("500","权限不合法");
        }else {
            throw new CustomerException("500","没有该角色");
        }
        return new ResponseData("200", "登录成功", resMap);
    }

    /**
     * 修改密码
     */
    @PutMapping("/updatePassword")
    public ResponseData updatePassword(@RequestBody Account account) {
        if ("SUPER_ADMIN".equals(account.getRole())) {
            sysAdminService.updatePassword(account);
        }
        else if ("ADMIN".equals(account.getRole())) {
            collegeAdminService.updatePassword(account);
        }
        else if("TEACHER".equals(account.getRole())){
            teacherService.updatePassword(account);
        }
        else if("STUDENT".equals(account.getRole())){
            studentService.updatePassword(account);
        }
        else if(account.getRole()==null || "".equals(account.getRole())){
            throw new CustomerException("500","权限不合法");
        }else {
            throw new CustomerException("500","没有该角色");
        }
        return new ResponseData("200", "修改密码成功");
    }
}
